package com.wb.proxy.cglib;

import com.wb.proxy.cglib.domain.Student;
import com.wb.proxy.cglib.interceptor.CglibInterceptor;
import com.wb.proxy.cglib.service.StudentService;
import com.wb.proxy.cglib.service.impl.StudentServiceImpl;
import net.sf.cglib.proxy.Enhancer;

/**
 * @author 魏彪
 */
public class TestCglib {

    public static void main(String[] args) {
        // 得到方法拦截器
        CglibInterceptor interceptor = new CglibInterceptor();
        // 使用Cglib框架生成目标类的子类，实现增强
        Enhancer enhancer = new Enhancer();
        // 设置父类字节码
        enhancer.setSuperclass(StudentServiceImpl.class);
        // 设置拦截处理
        enhancer.setCallback(interceptor);
        StudentService service = (StudentService) enhancer.create();
        // Student query = service.query();
        service.save(new Student());
    }
}
